# Contributor: Michael John <gosh.mike@gmail.com>
# Maintainer: Michael John <gosh.mike@gmail.com>
pkgname=azure-iot-sdk-c-static
pkgver=1.3.7
pkgrel=1
pkgdesc="Azure IoT SDK"
url="https://github.com/Azure/azure-iot-sdk-c"
arch="all"
license="MIT"
options="!check" # make check not implemented
makedepends="cmake openssl-dev openssl-libs-static libcurl curl-dev libuuid util-linux-dev busybox"
_azure_c_shared_utility_commit="48f7a556865731f0e96c47eb5e9537361f24647c"
_azure_umqtt_c_commit="65cdd1013715fb9d208c42f957eb353fbe22bafb"
_azure_uamqp_c_commit="142cfab9d66c6f81ea0cceb635f31e00cfa51c77"
_parson_commit="c5bb9557fe98367aa8e041c65863909f12ee76b2"
_uhttp_commit="b67a6bfa0d018a8a23176ee214e46c208fc323c3"
_riot_commit="bc97a5eaff53535eddbdf95b4f477c6caf3b7788"
_utpm_commit="afe8ad192502979e2b754c7d7c0b2e7178c78d09"
_azure_macro_utils_c_commit="5926caf4e42e98e730e6d03395788205649a3ada"
_umock_c_commit="5e3d93112360ee2d4a622b1c48eb70896da3e8c7"
_azure_c_testrunnerswitcher_commit="a33cd0a8524da8e45642baa112a506d4d2e5a59e"
_azure_ctest_commit="13baad856c3cb9e5457bff52bc8c2de87f21fa07"
source="$pkgname-$pkgver.tar.gz::https://github.com/Azure/azure-iot-sdk-c/archive/$pkgver.tar.gz
	$pkgname-$pkgver-azure_c_shared_utility.tar.gz::https://github.com/Azure/azure-c-shared-utility/archive/$_azure_c_shared_utility_commit.tar.gz
	$pkgname-$pkgver-azure_umqtt_c.tar.gz::https://github.com/Azure/azure-umqtt-c/archive/$_azure_umqtt_c_commit.tar.gz
	$pkgname-$pkgver-azure_uamqp_c.tar.gz::https://github.com/Azure/azure-uamqp-c/archive/$_azure_uamqp_c_commit.tar.gz
	$pkgname-$pkgver-parson.tar.gz::https://github.com/kgabis/parson/archive/$_parson_commit.tar.gz
	$pkgname-$pkgver-uhttp.tar.gz::https://github.com/Azure/azure-uhttp-c/archive/$_uhttp_commit.tar.gz
	$pkgname-$pkgver-riot.tar.gz::https://github.com/Microsoft/RIoT/archive/$_riot_commit.tar.gz
	$pkgname-$pkgver-utpm.tar.gz::https://github.com/Azure/azure-utpm-c/archive/$_utpm_commit.tar.gz
	$pkgname-$pkgver-azure_macro_utils_c.tar.gz::https://github.com/Azure/azure-macro-utils-c/archive/$_azure_macro_utils_c_commit.tar.gz
	$pkgname-$pkgver-umock_c.tar.gz::https://github.com/Azure/umock-c/archive/$_umock_c_commit.tar.gz
	$pkgname-$pkgver-azure_c_testrunnerswitcher.tar.gz::https://github.com/Azure/azure-c-testrunnerswitcher/archive/$_azure_c_testrunnerswitcher_commit.tar.gz
	$pkgname-$pkgver-azure_ctest.tar.gz::https://github.com/Azure/azure-ctest/archive/$_azure_ctest_commit.tar.gz
	001-c-utility.patch
	"
builddir="$srcdir/${pkgname%-static}-$pkgver"

prepare() {
	# adding submodules needed by azure-iot-sdk-c
	mv "$srcdir"/azure-c-shared-utility-$_azure_c_shared_utility_commit/* "$builddir"/c-utility/
	mv "$srcdir"/azure-umqtt-c-$_azure_umqtt_c_commit/* "$builddir"/umqtt/
	mv "$srcdir"/azure-uamqp-c-$_azure_uamqp_c_commit/* "$builddir"/uamqp/
	mv "$srcdir"/parson-$_parson_commit/* "$builddir"/deps/parson/
	mv "$srcdir"/azure-uhttp-c-$_uhttp_commit/* "$builddir"/deps/uhttp/
	mv "$srcdir"/RIoT-$_riot_commit/* "$builddir"/provisioning_client/deps/RIoT/
	mv "$srcdir"/azure-utpm-c-$_utpm_commit/* "$builddir"/provisioning_client/deps/utpm/
	mv "$srcdir"/azure-macro-utils-c-$_azure_macro_utils_c_commit/* "$builddir"/deps/azure-macro-utils-c/
	mv "$srcdir"/umock-c-$_umock_c_commit/* "$builddir"/deps/umock-c/
	mv "$srcdir"/azure-c-testrunnerswitcher-$_azure_c_testrunnerswitcher_commit/* "$builddir"/deps/azure-c-testrunnerswitcher/
	mv "$srcdir"/azure-ctest-$_azure_ctest_commit/* "$builddir"/deps/azure-ctest/

	default_prepare
}

build() {
	mkdir -p cmake-build
	cd cmake-build

	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi

	cmake \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
		-DCMAKE_C_FLAGS="$CFLAGS" \
		-Duse_amqp=OFF \
		${CMAKE_CROSSOPTS} ..
	cmake --build .
}

package() {
	cd "$builddir"/cmake-build
	make DESTDIR="$pkgdir" install
}

sha512sums="a6e9b15d42d91c7c5bd553317af1e4cc1bd84b87da447e476ad2c851db264aaab21da8d1816542cb7a6f12f0ca34a7e09349f6d0af3517567fdf3ff904ce48b3  azure-iot-sdk-c-static-1.3.7.tar.gz
c20074707e8601e090ee8daac1d96fdfb4f60ac60fd9c824dad81aa4c2f22b04733c82c01c1ae92110c26871b81674e8771d9ed65081f1c0c197a362275a28f1  azure-iot-sdk-c-static-1.3.7-azure_c_shared_utility.tar.gz
8cd33dcde966132e2aa0c6d931e75f9bcdc5734d57d8f6bb8a922711b0b63c2f0e58d379fe92371886387dfbb0b8c117b512873363eb76cf22fa985dbf11d52e  azure-iot-sdk-c-static-1.3.7-azure_umqtt_c.tar.gz
80f95bc969c2e50124622561b5f939e981a8d317e3e9514e52ce020f0f20a125622bf914f16927edafc7ff3c878fb1d6a28f4f5e66bda52dcc8aa2dc34761f73  azure-iot-sdk-c-static-1.3.7-azure_uamqp_c.tar.gz
8c9a4ebd4e2cccac17b21bc8e51e38b185b5b87ba7fb77321158751978bef2f40166acd8265e8b0589fb76b93998a40a09d5cd2030e59c3f01c6c4727b8abc0b  azure-iot-sdk-c-static-1.3.7-parson.tar.gz
75fafe242324bb2fc72befdd06427350e6f99aec9496fdf38b9660e7965fad89276ee543f36c3ba3360fc99b8301e74e2c1723d17f39e8471beee3e32cacb348  azure-iot-sdk-c-static-1.3.7-uhttp.tar.gz
e2655a4846c7ae15e1a0d3638b49e99dcb1d50b6aeb6ac9a85498be66e904af84d86ee1d739fa3122e539a5a1fdc125dcb679098be040f386bf4ec63c0679570  azure-iot-sdk-c-static-1.3.7-riot.tar.gz
75b7ac6a2686bb09fe0ff17c159d2b7043dca37a63f91939904e187955ce63c1736393bf16674ff25443cf1898a0b319ae4a326a12af5b733bc7fd54c86c0584  azure-iot-sdk-c-static-1.3.7-utpm.tar.gz
97621f276657af976c4022c9600540ecae2287b3b386b9e097d661828a62c120348d354b3f86f3ef4d49f3c54830887662d3910ed5cec4a634949fa389b4ad55  azure-iot-sdk-c-static-1.3.7-azure_macro_utils_c.tar.gz
9f5c0ce782f66a41e702e2d54dcff92b07b30e7c2be0ee2c63a56e2bff0c26a1de7f77abcb2a964d668deea817dcb3a4771e328707c2d982c23526465c950608  azure-iot-sdk-c-static-1.3.7-umock_c.tar.gz
c42350f39116dfdc3788d596ca22cf7e6040745e795c11ca1f6cb4fd63eeb2d913e89a1a50e8170612dea28b2a01306e04d865bd26046a10458ecffac3c0b6a1  azure-iot-sdk-c-static-1.3.7-azure_c_testrunnerswitcher.tar.gz
2f2dca81f101c33bf0a99c5e86012c0830686797b2934c7972c411f108ce0c31570988321cc58aabb3fcc0a2ecefbdab9dc950c7f922065b7bde8eb3207f2059  azure-iot-sdk-c-static-1.3.7-azure_ctest.tar.gz
419f71afc6be9e9ee27c11d5bdc7cad3e417ac3bd2d8cbb2a706c9be81ff88d99fb810bfc84a2424fefb2076e27f13bfaf14370e450c08ac09e8ebadfe1ac5cd  001-c-utility.patch"
